<?php

class ss_konstrukt_PhemtoAdapter extends k_PhemtoAdapter {
  public function injector() {
    return $this->injector;
  }
}

class ss_konstrukt_component extends k_Component{
	protected $settings;
	protected $injector;
	
	public function __construct(
			ss_core_configInterface $ss_settings,
			ss_core_injectorInterface $injector){
				//ss_error::log($injector);
		$this->injector=$injector;
		$this->settings=$ss_settings;
	}
	
	protected function injector(){
		return $this->injector;
	}
	
	public function level(){
		if(method_exists($this->context,'level')) return $this->context->level()+1;
		return 1;
	}
	
	public function settings($ss_settings=null){
		$this->settings=$ss_settings;
	}
	
	/*
	protected function renderJson() {
		return new k_JsonResponse(json_encode($this->content));
		$response=new k_HttpResponse(200, json_encode($this->content) ,true);
		$response->setContentType('application/json');
		throw $response;
	}
	*/
}

class ss_konstrukt_masterComponent extends ss_konstrukt_component{
	protected function getRange(){
		if($_range=$this->header('Range')){
			$_range=explode('-',substr($_range,strrpos($_range,'=')+1));
			return array($_range[0],$_range[1]-$_range[0]+1);
		}
		return false;
	}
	
	protected function getRi($ri,$type){
		//ss_error::log($ri,'RI');
		$ri['template']=$type.'_'.$ri['template'];
		foreach($ri['levels'] as $key=>$val){
			if(!is_array($val)) $val=array('num'=>$val);
			if(isset($val['template'])){
				$base=$type.'_'.$val['template'];
			} else {
				$base=$ri['template'].ucfirst($key);
			}
			$file=$base.'_'.$this->document->getLanguage().'.tpl';
			if(file_exists(SITE_ROOT_PATH . '/templates/'.$file)){
				$val['template']=$file;
			} else {
				$val['template']=$base.'.tpl';
			}
			ss_error::log($file,'testing lang');
			$ri['levels'][$key]=$val;
		}
		return $ri;
	}
}

class ss_konstrukt_detailComponent extends ss_konstrukt_masterComponent{
	
	/*protected function renderJson() {
		$this->content=array($this->content);
		parent::renderJson();
	}*/
	
}
?>